//
//  MYShipinshouchang;.m
//  Tour
//
//  Created by 张张烨 on 16/3/16.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "MYShipinshouchang;.h"
#import "MYShipinshouchangModel.h"
#import "DsErErCell.h"
@interface MYShipinshouchang_ ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
@property (nonatomic, strong) BaseTableView *tableView;

@property (nonatomic, strong) NSMutableArray *arr;

@end

@implementation MYShipinshouchang_

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.arr = [NSMutableArray array];
    self.arr = [[DataKu shareInstance] selet];
    
    [self tableView1];
}


- (void)tableView1
{
    self.tableView = [[BaseTableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    
    self.tableView.dataSource = self;
    
    self.tableView.delegate = self;
    
    [self.view addSubview:_tableView];
    
    [self.tableView registerClass:[DsErErCell class] forCellReuseIdentifier:@"cell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DsErErCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    MYShipinshouchangModel * m = _arr[indexPath.row];
    
    [cell.picture sd_setImageWithURL:[NSURL URLWithString:m.tupian]];
    cell.littleLabel.text = m.shichang;
    cell.titleLabel.text = m.mingzi;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    
    NSArray<DsErErCell *> *array = [self.tableView visibleCells];
    [array enumerateObjectsUsingBlock:^(DsErErCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj cellOffset];
    }];
    
}
// 通过编辑状态判断编辑操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    // 通过参数editingStyle判断 执行不同操作
    // 删除操作
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // 删除操作分两部分: 数据/视图
        // 先操作数据 再同步更新视图
        // 1.从数组中 删除数据
        //    WodeshouchangMoble * m = _dataArr[indexPath.row];
        
        
        // 2.同步视图
        
        // 参数1: 视图操作的cell位置
        // 参数2: 操作的动画选项

        
        [[DataKu shareInstance] deleteNumber:[_arr[indexPath.row] mingzi]];
        
        [_arr removeObjectAtIndex:indexPath.row];
        
        
        [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    
    [_tableView reloadData];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
